package com.transaction.simulate.service.impl;

import com.transaction.simulate.mapper.ChannelMapper;
import com.transaction.simulate.model.dto.Channel;
import com.transaction.simulate.service.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    private ChannelMapper channelMapper;

    @Override
    public List<Channel> getChannel(Channel channel) {
        List<Channel> list =  channelMapper.getChannel(channel);
        return list;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void addChannel(Channel channel) {
        channel.setDealFileTypes(String.join(",",channel.getDealFileList()));
        channelMapper.addChannel(channel);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int deleteChannel(List<Channel> channelList) {
        return channelMapper.deleteChannel(channelList);
    }
}
